package com.kmust.dream.wanderingdream.product.controller;

import com.kmust.dream.wanderingdream.comm.pojo.ResultBean;
import com.kmust.dream.wanderingdream.product.entity.ProductPropertyValue;
import com.kmust.dream.wanderingdream.product.service.ProductPropertyValueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product/propertyValue")
@Api("商品属性值API")
public class ProductPropertyValueController {

    @Autowired
    ProductPropertyValueService productPropertyValueService;


    /**
     * 主键获取
     * @param valueId 主键
     * @return resultBean
     */
    @ApiOperation(value = "主键获取键值",notes = "参数是主键")
    @GetMapping("/getPropertyValueByValueId/{valueId}")
    public ResultBean getProductPropertyValueById(@PathVariable Integer valueId) {
        return productPropertyValueService.getProductPropertyValueById(valueId);
    }

    /**
     * 属性名称id获取值
     * @param nameId 属性名称id
     * @return resultBean
     */
    @ApiOperation(value = "属性名称id获取值",notes = "参数是属性名称id")
    @GetMapping("/getPropertyValueByNameId/{nameId}")
    public ResultBean getProductPropertyValueByNameById(@PathVariable Integer nameId) {
        return productPropertyValueService.getProductPropertyValueByNameById(nameId);
    }

    /**
     * 获取所有的属性对对象
     * @return resultBean
     */
    @ApiOperation(value = "获取所有的属性对对象",notes = "无参数")
    @GetMapping("/getPropertyValues")
    public ResultBean getPropertyValues() {
        return productPropertyValueService.getPropertyValues();
    }

    /**
     * 添加属性值
     * @param productPropertyValue 属性值对象
     * @return resultBean
     */
    @ApiOperation(value = "添加属性值",notes = "参数是属性值对象json")
    @PostMapping("/addPropertyValue")
    public ResultBean addPropertyValue(@RequestBody ProductPropertyValue productPropertyValue) {
        return productPropertyValueService.addPropertyValue(productPropertyValue);
    }

    /**
     * 更新属性值对象
     * @param productPropertyValue 属性值对象
     * @return resultBean
     */
    @ApiOperation(value = "更新属性值对象",notes = "参数是属性值对象json")
    @PutMapping("/updatePropertyValue")
    public ResultBean updatePropertyValue(@RequestBody ProductPropertyValue productPropertyValue) {
        return productPropertyValueService.updatePropertyValue(productPropertyValue);
    }

    /**
     * 根据主键删除属性值对象
     * @param valueId 主键
     * @return resultBean
     */
    @ApiOperation(value = "根据主键删除属性值对象",notes = "参数是主键")
    @DeleteMapping("/deletePropertyValueByValueId/{valueId}")
    public ResultBean deletePropertyValue(@PathVariable Integer valueId) {
        return productPropertyValueService.deletePropertyValue(valueId);
    }
}
